package sg.edu.nus.iss.cerberus.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

/**
 * @author Priyanka (a0065715)
 * 
 * */

@SuppressWarnings("serial")
public class CClass implements Serializable{
	
		private String className;
		private HashMap <String,ArrayList<CMemberMethod>> methodHash ;
		private String accessModifier;
		private ArrayList<CMemberVariable> attributes;
		private ArrayList<CConstructor> constructors;

		public CClass(){
			super();
			this.className = null;
			this.methodHash = null;
			this.accessModifier = null;
			this.attributes = null;
			this.constructors=null;
			
		}
		
		public CClass(String className, HashMap<String, ArrayList<CMemberMethod>> methodHash,
				String accessModifier, ArrayList<CMemberVariable> attributes, ArrayList<CConstructor> constructorArray) {
			super();
			this.className = className;
			this.methodHash = methodHash;
			this.accessModifier = accessModifier;
			this.attributes = attributes;
			this.constructors = constructorArray;
		}
		
		
		public String getClassName() {
			return className;
		}
		public void setClassName(String className) {
			this.className = className;
		}
		public HashMap<String, ArrayList<CMemberMethod>> getMethodHash() {
			return methodHash;
		}
		public void setMethodHash(HashMap<String, ArrayList<CMemberMethod>> methodHash) {
			this.methodHash = methodHash;
		}
		public String getAccessModifier() {
			return accessModifier;
		}
		public void setAccessModifier(String accessModifier) {
			this.accessModifier = accessModifier;
		}
		public ArrayList<CMemberVariable> getAttributes() {
			return attributes;
		}
		public void setAttributes(ArrayList<CMemberVariable> attributes) {
			this.attributes = attributes;
		}
		
		public ArrayList<CMemberMethod> getMethod(String name)
		{
			return methodHash.get(name);
		}
	
		public void setMethod(String name,ArrayList<CMemberMethod> method)
		{
			 methodHash.put(name,method);

		}
		
		public void setMethod(String name, CMemberMethod method)
		{
			if(methodHash.get(name)!=null)
			{	
				methodHash.get(name).add(method);

			}
			 else{
				ArrayList<CMemberMethod> newCMethod=new ArrayList<CMemberMethod>();
				newCMethod.add(method);
				methodHash.put(name, newCMethod);
			}	
		}
	
		public boolean isConstructor(String name){
			boolean flag = false;
			Iterator<CConstructor> i = constructors.iterator();
			while(i.hasNext() && i.next() != null)
				if(i.next().getMethodName().equals(name))
					flag = true;
			return flag;
		}
		
		public CConstructor getDefaultConstructor(){
			for(int i = 0; i < constructors.size(); i ++)
				if(constructors.get(i).isDefault())
					return constructors.get(i);
			return null;
		}
		
		public ArrayList<CConstructor> getConstructors() {
			return constructors;
		}
		
		public void setConstructors(ArrayList<CConstructor> constructors) {
			this.constructors = constructors;
		}
	}


